Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish author viewpoint page #11

Open
wants to merge 11 commits into
base: development
Choose a base branch
from
Open

Conversation

yukicoder0509
Copy link
Collaborator

I have finished author-viewpoint page and fixed some center layout problems and adjust the height setting of each page.

Copy link

vercel bot commented Nov 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 5, 2024 0:33am

src/app/issues/[id]/author/page.tsx Outdated Show resolved Hide resolved
src/app/issues/[id]/author/page.tsx Outdated Show resolved Hide resolved
src/app/issues/[id]/author/page.tsx Outdated Show resolved Hide resolved
src/app/issues/[id]/author/page.tsx Outdated Show resolved Hide resolved
src/components/AuthorViewpoint/FactCard.tsx Outdated Show resolved Hide resolved
src/components/AuthorViewpoint/FactCard.tsx Outdated Show resolved Hide resolved
src/components/AuthorViewpoint/FactCard.tsx Outdated Show resolved Hide resolved
src/components/AuthorViewpoint/ViewpointCard.tsx Outdated Show resolved Hide resolved
@burnedinthesky
Copy link
Contributor

In addition, per the design file, please remember to add a 6px padding between paragraphs.

Copy link
Contributor

@burnedinthesky burnedinthesky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All previous issues have been resolved except for the paragraph spacing. By paragraph spacing I mean additional padding between paragraphs of text (created by pressing the enter key). Paragraph spacing should be in addition to line height. For example: the distance between text "Line 1 \n Line 2" should be 6px more than "Line 1..... [line-wrap] line 2".

};
};

type MetadataProps = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused props type

Copy link
Contributor

@burnedinthesky burnedinthesky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for missing this in the last review, but I think there's a major misunderstanding in where the facts in the FactListCard come from. The facts are not automatically imported from the issue (since there may be hundreds if not thousands of facts per issue), but instead the user gets an empty list, and adds facts to the list by referenceing existing facts (via the search bar) or authoring new facts (via the fact creation feature). Please edit your code to reflect this system design.

<ViewpointCard />
</div>
<div className="w-1/3">
<FactListCard facts={issue.facts} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there may be hundreds or thousands of facts per issue, we by default will show only an empty list of facts when the user loads the author viewpoint page. Any fact that appears in the reference area must either be there because (a) a user searched for & added it via the search bar or (b) a user created a fact when authoring this viewpoint

};

export default function FactListCard({ facts }: FactListCardProps) {
const [searchData] = useState<string[]>([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remember to define the setSearchData returned as well. If eslint warns you for unused variables, consider disabling that rule for this line temporarily (guide to how), or better, move the mock data to the server response for keyword search, and implement the "select fact to reference" function in this PR.

classNames={{
input: "ml-2 bg-transparent text-lg font-normal text-neutral-500 focus-within:outline-b-2 focus-within:border-b-emerald-500 focus-within:outline-none",
}}
placeholder="搜尋 CommonGround"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the option to import a fact when nothing is found (Mantine reference)

+ 92px(FactListCard title and search box) + 16px(FactListCard padding-bottom)*/}
<div className="flex flex-col gap-3 pl-7 pr-4">
{facts.map((fact) => (
<div key={fact.id}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the outer div is unnecessary, just <EditViewpointFact key={fact.id} fact={fact}> should do

variant="transparent"
leftSection={<PlusIcon className="h-6 w-6" />}
classNames={{
root: "px-0 ml-7 mt-2 text-neutral-600 text-base font-normal hover:text-emerald-500 duration-300",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current styling results in a padding whether there are facts before this or not. It makes less sense to add a padding here since the searchbar already has a y-padding. Consider moving the Button into the flexbox and utilizing the gap property.

@@ -0,0 +1,51 @@
"use client";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should not be included in this branch as the scope of this PR does not include networking

<Button
variant="transparent"
classNames={{
root: "float-right pr-1 pl-0 flex opacity-0 group-hover:opacity-100",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using the hidden class instead of setting opacity

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To prevent layout shifts when toggling the visibility of an element, instead of using display to show or hide it—which removes the element from the layout entirely—I use the visibility property. This approach visually hides the element while keeping its space reserved in the layout, ensuring a stable and consistent page structure.

viewpointFactList,
setViewpointFactList,
}: FactListCardProps) {
const [searchData, setSearchData] = useState<Fact[]>(allFacts); // eslint-disable-line
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since both attributes are used, this line shouldn't be ignored by eslint.

const id = params.id;

return (
<main className="mx-auto my-8 w-full max-w-7xl">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this page doesn't have much content and is mostly client-side logic, I think we can consider making this page completely client-side rendered and move all login into AuthorViewpointCard.


const onPublish = () => {
if (viewpointTitle == "" || contentEmpty) {
console.log("Title and Content MUST NOT be empty");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a toast to display this message to the user as most users won't check the JS console

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Furthermore, if the message were to appear in a toast, please translate the message into Chinese.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The console is added to check if the logic works when developing.

if (node.className.includes("pt-1.5")) return;
node.classList.add("pt-1.5");
});
setViewpointContent(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this trigger are quite frequent, this may result in common costly rerenders that slow the application down. Also, considering that the content of this div is not controlled, I think we can consider moving this event into onBlur

(fact) => String(fact.id) == selectedFactId,
);
if (selectedFact) {
//move the selected fact to the viewpointFactList
Copy link
Contributor

@burnedinthesky burnedinthesky Dec 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When writing mutations that reply on previous state it is not recommended to take the state variable as they do not update until re-rendered, which is not triggered immediately and instead can be batched. The current method results in race conditions and using useState(prev => [...prev, new]) is recommended

);
setSearchData(newSearchData);
}
}, [selectedFactId, setSelectedFactId]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the linter warning

const newSelectedFacts = viewpointFactList.filter(
(fact) => String(fact.id) !== factId,
);
setViewpointFactList(newSelectedFacts);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same applies here, consider basing filters on data passed in by the setState hook instead of relying on the state variable

);
setSearchData(newSearchData);

console.log(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary logging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants